jQuery(document).ready(function() {
	/*
	var prodname1h = jQuery("#prodname1").height();
	var prodname2h = jQuery("#prodname2").height();
	if(prodname1h > prodname2h) {
		jQuery("#prodname2").height(jQuery("#prodname1").height());
	} else {
		jQuery("#prodname1").height(jQuery("#prodname2").height());
	}
	*/
	var current_pos = getCookie("fb_current_pos");
	if (current_pos > 1) {
		//console.log(current_pos + "TRUE");
		if(current_pos=="2") {
		jQuery("div.wizard a:nth-of-type(1)").attr("class","current done");
		jQuery("div.wizard a:nth-of-type(2)").attr("class","current");
		jQuery("div.wizard a:nth-of-type(3), div.wizard a:nth-of-type(4), div.wizard a:nth-of-type(5)").removeAttr("href");
		}
		if(current_pos=="3") {
		jQuery("div.wizard a:nth-of-type(1), div.wizard a:nth-of-type(2)").attr("class","current done");
		jQuery("div.wizard a:nth-of-type(3)").attr("class","current");
		jQuery("div.wizard a:nth-of-type(4), div.wizard a:nth-of-type(5)").removeAttr("href");
		
		  var mode = getCookie("fb_mode");
		  var promo = getCookie("fb_promo");
		  var commitmentBox = getCookie("fb_commitmentBox");
		  
          if(mode!="edit"){      
			jQuery(".promoBox, .commitmentBox").addClass("active");
			jQuery('#pname, #pemail, #pdob, #padd').hide();
			jQuery('#promo').html(promo);
			jQuery('#commitmentBox').text(commitmentBox);
		  }
		}
		if(current_pos=="4") {
		jQuery("div.wizard a:nth-of-type(1), div.wizard a:nth-of-type(2),div.wizard a:nth-of-type(3)").attr("class","current done");
		jQuery("div.wizard a:nth-of-type(4)").attr("class","current");
		jQuery("div.wizard a:nth-of-type(5)").removeAttr("href");
		
		  var mode = getCookie("fb_mode");
		  var promo = getCookieR("fb_promo");
		  var commitmentBox = getCookieR("fb_commitmentBox");
		  var mobtel = getCookieR("fb_mobtel");
		  
          if(mode!="edit"){      
			jQuery(".promoBox, .commitmentBox, .prepaidBox").addClass("active");
			jQuery('#pname, #pemail, #pdob, #padd').hide();
			jQuery('#promo').html(promo);
			jQuery('#commitmentBox').text(commitmentBox);
			jQuery('#mobtel').text(mobtel);
		  }
		}
		if(current_pos=="5") {
		jQuery("div.wizard a:nth-of-type(1),div.wizard a:nth-of-type(2),div.wizard a:nth-of-type(3),div.wizard a:nth-of-type(4)").attr("class","current done");
		jQuery("div.wizard a:nth-of-type(5)").attr("class","width100 current");
		
		  var mode = getCookie("fb_mode");;
		  var promo = getCookieR("fb_promo");
		  var commitmentBox = getCookieR("fb_commitmentBox");
		  var mobtel = getCookieR("fb_mobtel");
		  var username = getCookieR("fb_username");
		  var eadd = getCookieR("fb_eadd");
		  var bday = getCookieR("fb_bday");
		  var address = getCookieR("fb_address");
		  
          if(mode!="edit"){ 
			jQuery(".promoBox, .commitmentBox, .prepaidBox, .profileBox").addClass("active");
			jQuery(".pnone").hide();
			jQuery('#promo').html(promo);
			jQuery('#commitmentBox').text(commitmentBox);
			jQuery('#mobtel').text(mobtel);
			jQuery('#name').text(username);
			jQuery('#email').text(eadd);
			jQuery('#dob').text(bday);
			jQuery('#add').text(address);
			jQuery("#pname, #pemail, #pdob, #padd").show();
		  }
		}
	} else {
		//console.log(current_pos + "FALSE");
		jQuery("div.wizard a:nth-of-type(1), div.wizard a:nth-of-type(2), div.wizard a:nth-of-type(3), div.wizard a:nth-of-type(4), div.wizard a:nth-of-type(5)").removeAttr("href");
	} 
	
	var base_url = baseurl;

        var maitainumbercompare = getCookie("fb_maitainumbercompare");

        if(maitainumbercompare=="2") {
          jQuery("#add-another-device").hide();
		  jQuery(".compA div:nth-of-type(4)").removeClass("bordRight");
		  jQuery(".compB div:nth-of-type(3), .compC div:nth-of-type(3), .compD div:nth-of-type(3), .compE div:nth-of-type(3), .compF div:nth-of-type(3), .compG div:nth-of-type(3)").removeClass("bordRight");
		  jQuery(".compB div:nth-of-type(4), .compC div:nth-of-type(4), .compD div:nth-of-type(4), .compE div:nth-of-type(4), .compF div:nth-of-type(4), .compG div:nth-of-type(4)").remove();
		}

        if(maitainumbercompare=="0") {
          alert("Your comparison list is empty");
	}
	
	jQuery('.compare-sku1').click(function(){
	     document.cookie="fb_current_pos=" + "2" + "; path=/";
	     var sku = jQuery(".compare-sku1").attr('id');
	     var maitaicompare1 = getCookie("fb_maitaicompare1");
	     var maitaicompare2 = getCookie("fb_maitaicompare2");
	     var maitainumbercompare = getCookie("fb_maitainumbercompare");

	     if(maitainumbercompare=="1") {
	       document.cookie="fb_maitainumbercompare=" + "0" + "; path=/";
	       
	       if(sku==maitaicompare1){
		 document.cookie="fb_maitaicompare1=" + "" + "; path=/";
		 document.cookie="fb_maitaicompare2=" + "" + "; path=/";
		 window.location=base_url + "gallery";
	       }	   

	     }
		
	     if(maitainumbercompare=="2") {
	       document.cookie="fb_maitainumbercompare=" + "1" + "; path=/";
	       
	       if(sku==maitaicompare1){
		 document.cookie="fb_maitaicompare1=" + maitaicompare2 + "; path=/";
		 document.cookie="fb_maitaicompare2=" + "" + "; path=/";
	       } 

	       if(sku==maitaicompare2)
		 document.cookie="fb_maitaicompare2=" + "" + "; path=/";
	       
	       window.location=base_url + "compare";
	     }
	     
		  
	}); 

	jQuery('.compare-sku2').click(function(){
	     document.cookie="fb_current_pos=" + "2" + "; path=/";
	     var sku = jQuery(".compare-sku2").attr('id');
	     var maitaicompare1 = getCookie("fb_maitaicompare1");
	     var maitaicompare2 = getCookie("fb_maitaicompare2");
	     var maitainumbercompare = getCookie("fb_maitainumbercompare");

	     if(maitainumbercompare=="1") {
	       document.cookie="fb_maitainumbercompare=" + "0" + "; path=/";
	       
	       if(sku==maitaicompare1){
		 document.cookie="fb_maitaicompare1=" + "" + "; path=/";
		 document.cookie="fb_maitaicompare2=" + "" + "; path=/";
		 window.location=base_url + "gallery";
	       } 

	     }
		
	     if(maitainumbercompare=="2") {
	       document.cookie="fb_maitainumbercompare=" + "1" + "; path=/";
	       
	       if(sku==maitaicompare1){
		 document.cookie="fb_maitaicompare1=" + maitaicompare2 + "; path=/";
		 document.cookie="fb_maitaicompare2=" + "" + "; path=/";
	       } 

	       if(sku==maitaicompare2)
		 document.cookie="fb_maitaicompare2=" + "" + "; path=/";
	       
	       window.location=base_url + "compare";
	     }
		  
	}); 

	jQuery('.get-sku1').click(function(){
	     var sku = jQuery(".compare-sku1").attr('id');
		 var price1 = jQuery('#price1').text();
		 //price1 = price1.substring(4);
	     document.cookie="fb_sku=" + sku + "; path=/";	
	     document.cookie="fb_gadget=" + jQuery('#prodname1').text() + "; path=/"; 
	     document.cookie="fb_price=" + price1 + "; path=/";
		 document.cookie="fb_imgsrc=" + jQuery(".compare-img1").attr('src') + "; path=/";		 
	}); 

	jQuery('.get-sku2').click(function(){
	     var sku = jQuery(".compare-sku2").attr('id');
	     var price2 = jQuery('#price2').text();
		 //price2 = price2.substring(4);
		 document.cookie="fb_sku=" + sku + "; path=/";	
	     document.cookie="fb_gadget=" + jQuery('#prodname2').text() + "; path=/"; 
	     document.cookie="fb_price=" + price2 + "; path=/";
		 document.cookie="fb_imgsrc=" + jQuery(".compare-img2").attr('src') + "; path=/";	
	}); 


});


function getCookie(fb_cname)
{
var name = fb_cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) 
  {
  var c = ca[i].replace(/\s/g, "");
  if (c.indexOf(name)==0) return c.substring(name.length,c.length);
  }
return "";
}